package csxXiti.xiti3;

class xiti3_1 {
    public static void main(String[] args) {
        /*如果fruit不加abstract方法,不需要JuiceMachine类,就可以直接调用
         * Fruit f = new Apple();
         * f.flow();*/
        JuiceMachine jm = new JuiceMachine();
        //Fruit为抽象类,不可以创建对象
        //Fruit ff = new Fruit();
        //子类对象可以传给抽象的父类引用,
        Fruit f = new Apple();
        jm.makeJuice(f);
        f = new Orange();
        jm.makeJuice(f);
        jm.makeJuice(new Banana());
    }
}

//榨汁机类
class JuiceMachine {
    //多态的使用,Fruit这个父类作为形式参数
    public void makeJuice(Fruit f) {
        f.flow();
    }
}

//水果抽象类
abstract class Fruit {
    abstract public void flow();
}

//苹果类
class Apple extends Fruit {

    @Override
    public void flow() {
        System.out.println("流出苹果汁");
    }
}

//橙子类
class Orange extends Fruit {
    @Override
    public void flow() {
        System.out.println("流出橙汁");
    }
}

//香蕉类
class Banana extends Fruit {
    @Override
    public void flow() {
        System.out.println("流出香蕉酱");
    }
}